#pragma once

#include <iostream>
#include <vector>
#include <unistd.h>
using namespace std;

//函数指针
typedef void (*func_t)();

//定义操作码，设置每一个command都是4字节
#define LOG 0
#define SQL 1
#define RQUEST 2

void PrintLog(){
    cout << "pid: " << getpid() <<" PrintLog..." << endl;
}

void InsertSQL(){
    cout << "pid: " << getpid() << " InsertSQL..." << endl;
}

void NetRequest(){
    cout << "pid: " << getpid() << " NetRequest..." << endl;
}

class Task{
public:
    Task(){
        //往Task中放入三个任务
        funcs.push_back(PrintLog);
        funcs.push_back(InsertSQL);
        funcs.push_back(NetRequest);
    }

    ~Task(){

    }

    //根据传入的命令执行任务
    void Execute(int command){
        if(command >=0 && command<funcs.size()){
            //执行下标为command的函数
            funcs[command]();
        }
    }

public:
    vector<func_t> funcs;
};


